package com.bojiu.lawsearch.lawsearch.controller;

import com.bojiu.lawsearch.lawsearch.model.Log;
import com.bojiu.lawsearch.lawsearch.model.Page;
import com.bojiu.lawsearch.lawsearch.service.LogService;
import com.bojiu.lawsearch.lawsearch.util.AuthorizationHandle;
import com.bojiu.lawsearch.lawsearch.util.Constances;
import com.bojiu.lawsearch.lawsearch.util.JsonResult;
import com.bojiu.lawsearch.lawsearch.util.ResultCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: afdiao
 * @Date：2020/4/14 15:33
 * @Description:
 */
@Api(description = "积分以及金额变动明细")
@RestController
@RequestMapping("log")
public class BackLogController {

    @Autowired
    AuthorizationHandle authorizationHandle;

    @Autowired
    private LogService logService;

    /**
     * 积分或金额变动列表
     *
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @ApiOperation(value = "积分或金额变动列表", notes = "获取积分或金额变动列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = Log.class),
            @ApiResponse(code = 600, message = "未检测到登录，跳转重新登录"),
            @ApiResponse(code = 500, message = "没有权限访问该接口")
    })
    @GetMapping("list/{pageNum}/{pageSize}")
    public JsonResult getTaskList(@ApiParam(name = "pageNum", value = "当前页码", required = true) @PathVariable("pageNum") int pageNum,
                                  @ApiParam(name = "pageSize", value = "每页个数", required = true) @PathVariable("pageSize") int pageSize,
                                  @ApiParam(name = "type", value = "类型（1-积分历史，2-余额历史）", required = true) int type,
                                  HttpServletRequest request) {
        //先判断权限
        JsonResult authon = authorizationHandle.backHandler(request, Constances.ALL);
        if (!authon.getCode().equals("200")) {
            return authon;
        }
        Log log = new Log();
        log.setType(type);
        Page<Log> taskList = logService.queryPage(pageNum, pageSize, log);
        return new JsonResult(ResultCode.SUCCESS, taskList);
    }
}
